home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / relnotesTOC.z / relnotesTOC
Text File  |  2002-10-15  |  7KB  |  333 lines

  1. #!/usr/bin/perl
  2.  
  3. require 5;
  4.  
  5. $bgcolor    ="#f9f9f9";
  6. $doctype    = "<!DOCTYPE HTML PUBLIC \"-//Netscape " .
  7.               "Comm. Corp.//DTD HTML//EN\">\n";
  8. $comment    = "<!-- Generated by infosearch relnotesTOC -->\n";
  9. $bHTML      = "<HTML>\n";
  10. $eHTML      = "</HTML>\n";
  11. $bTitle     = "<HEAD>\n    <TITLE>";
  12. $eTitle     = "</TITLE>\n</HEAD>\n";
  13. $bBody      = "<BODY BGCOLOR=\"$bgcolor\">";
  14. $eBody      = "</BODY>\n";
  15. $cgiBase    = "<A HREF=\"/cgi-bin/infosrch.cgi?cmd=getdoc&db=relnotes&fname=";
  16. $bBQ        = "<P>";
  17. $eBQ        = "</P>";
  18.  
  19. $sgiIndex   = "/usr/relnotes/SGIindex/relnotes.ttl";
  20.  
  21.  
  22. $arg1 = $ARGV[0];
  23.  
  24. # if -coll then add "&coll=" to the getdoc URL
  25. if ($ARGV[1] eq "-coll" && $cgiBase =~ /(.*)&db=relnotes(.*)/) {
  26.    $cgiBase = $1 . "&coll=" . $ARGV[2] . "&db=relnotes" . $2;
  27.    shift; shift;
  28. }
  29.  
  30. if ($arg1 eq ""){
  31.     &buildFTIndexList("$sgiIndex");
  32. }elsif($arg1=~/\.ttl/){
  33.     &buildFTIndexList($arg1);
  34. }elsif($arg1=~/relnotes\.html/){
  35.     &buildTOCnoIndex();  # fallback index to STDOUT
  36. }
  37.  
  38. #######################################################################
  39. #
  40. # buildFTIndexList()
  41. #
  42. #######################################################################
  43.  
  44.  
  45. sub buildFTIndexList{
  46.  
  47.     local($titlefiles) = @_;
  48.     local($inBQ) = 0;
  49.     local($lastAlpha) = "";
  50.     local($thisAlpha) = "";
  51.  
  52.     unless( -r $titlefiles ){
  53.     die "Unable to read $titlefiles\n";
  54.     }
  55.     
  56.     $mainIndexTTL  = $titlefiles;
  57.     $htmlTOC       = $titlefiles;
  58.     $htmlTOC       =~ s/\.ttl/\.html/;
  59.  
  60.     $localIndexTTL = $mainIndexTTL;
  61.     $localIndexTTL =~ s/([^\/]*)\.ttl$/local$1\.ttl/; 
  62.     
  63.     # Only if the local file exists (else strings error)
  64.     if ( -e $localIndexTTL ){
  65.     $titlefiles = "$titlefiles $localIndexTTL"; 
  66.     }
  67.     
  68.     open(TITLESTR, "strings $titlefiles | " ) 
  69.     || die "Error: Can't open $titlefiles\n";
  70.     
  71.     @titledata=();
  72.     @toclist=();
  73.     
  74.     while(<TITLESTR>){    
  75.     
  76.     if (/^F(.+)\n/){
  77.         # Take the filename exactly as it appears in the index
  78.         # title file (.ttl file).
  79.         $filename=$1;
  80.     }elsif(/^t(.+)\n/){
  81.         
  82.         push(@titledata, $1);
  83.         push(@toclist, "$1\t$filename");
  84.         
  85.     } 
  86.     }
  87.     close(TITLESTR);
  88.  
  89.     @toclist = sort sortCaseInsensitive @toclist;
  90.  
  91.     system("rm -f $htmlTOC");
  92.  
  93.     open(TOCFD,">> $htmlTOC") 
  94.     || die "Can't open $htmlTOC\n";
  95.     
  96.     &HTMLFileHeader(TOCFD,"Product Release Notes");
  97.     &alphaHeader(TOCFD);
  98.  
  99.     foreach(@toclist){
  100.  
  101.     if(/([^\t]+)\t([^\t]+)/ && ($prod = $1, $file = $2)){
  102.         $file =~ s/\+/%2b/g; # Files with + break the cgi
  103.  
  104.         $thisAlpha=&setAlpha($prod);
  105.         &alphaIndexIfNeeded($inBQ,TOCFD,$lastAlpha,$thisAlpha);
  106.         $lastAlpha = $thisAlpha;
  107.         
  108.         if($inBQ == 0){ # Correct indentation
  109.         $indent = $bBQ;
  110.         $inBQ = 1;
  111.         }else{
  112.         $indent = "";
  113.         }        
  114.         
  115.         print TOCFD 
  116.         "  ",
  117.         "$cgiBase$file\">$prod</A><BR>\n"
  118.           or die "print: $!";
  119.     }
  120.     
  121.     }
  122.  
  123.     &HTMLFileTrailer(TOCFD);
  124.  
  125. }
  126.  
  127. #######################################################################
  128. #
  129. # buildTOCnoIndex
  130. #
  131. # Build a table of contents from relnote files
  132. #
  133. #######################################################################
  134.  
  135. sub  buildTOCnoIndex{
  136.  
  137.  
  138.     local($inBQ) = 0;
  139.     local($lastAlpha) = "";
  140.     local($thisAlpha) = "";
  141.     local(@relprods)  = ();
  142.     local($relpath)   = $ENV{'RELNOTESPATH'};
  143.     
  144.     if($relpath eq ""){
  145.     $relpath = "/usr/relnotes";
  146.     }
  147.  
  148.     $relfind = "find $relpath -name TC -print"; 
  149.  
  150.     open(RELFIND,"$relfind |") 
  151.     || die "Can't open $htmlTOC\n";
  152.  
  153.     while(<RELFIND>){
  154.     if(/\/([^\/]+)\/TC/){
  155.         push(@relprods,$1);
  156.     }
  157.     }
  158.  
  159.     @relprods = sort sortCaseInsensitive @relprods;
  160.  
  161.     &HTMLFileHeader(STDOUT,"Product Release Notes");
  162.     &alphaHeader(STDOUT);
  163.  
  164.     foreach(@relprods){
  165.     
  166.     $cgitrans = $_;
  167.     $cgitrans =~ s/\+/%2b/g; # Products with '+' break the cgi
  168.  
  169.     $thisAlpha=&setAlpha($_);
  170.     &alphaIndexIfNeeded($inBQ,STDOUT,$lastAlpha,$thisAlpha);
  171.     $lastAlpha = $thisAlpha;
  172.     
  173.     if($inBQ == 0){ # Correct indentation
  174.         $indent = $bBQ;
  175.         $inBQ = 1;
  176.     }else{
  177.         $indent = "";
  178.     }
  179.     
  180.     print  
  181.         "${indent}",
  182.         "$cgiBase$cgitrans\">$_</A><BR>\n"
  183.           or die "print: $!";
  184.     }
  185.  
  186.     &HTMLFileTrailer(STDOUT);
  187. }
  188.  
  189. #######################################################################
  190. #
  191. # HTMLFileHeader(fd, title)
  192. #
  193. #######################################################################
  194.  
  195. sub HTMLFileHeader{
  196.  
  197.     local($filehandle,$title)= @_;
  198.     
  199.     print { $filehandle } 
  200.     "$doctype$comment$bHTML$bTitle$title$eTitle$bBody\n"
  201.           or die "print: $!";
  202.  
  203.     print { $filehandle } 
  204.     "<H3>$title</H3>\n"
  205.       or die "print: $!";
  206. }
  207.  
  208. #######################################################################
  209. #
  210. # HTMLFileTrailer(fd)
  211. #
  212. #######################################################################
  213.  
  214. sub HTMLFileTrailer{
  215.  
  216.     local($filehandle) = @_;
  217.     
  218.     print { $filehandle }  "${eBQ}${eBody}${eHTML}"
  219.       or die "print: $!";
  220. }
  221.  
  222. #######################################################################
  223. #
  224. # sortCaseInsensitive
  225. #
  226. #######################################################################
  227.  
  228. sub sortCaseInsensitive
  229. {           
  230.     local($tmp_a) = $a;
  231.     local($tmp_b) = $b;
  232.  
  233.     $tmp_a =~ tr/A-Z/a-z/;
  234.     $tmp_b =~ tr/A-Z/a-z/;
  235.     
  236.     return($tmp_a cmp $tmp_b);
  237. }
  238.  
  239.  
  240. #######################################################################
  241. #
  242. # setAlpha(titleString)
  243. #
  244. #######################################################################
  245.  
  246. sub setAlpha{
  247.  
  248.     local($title) = @_;
  249.     local($alpha) = "";
  250.  
  251.     if($title=~/^([a-zA-Z])/){
  252.     $alpha=$1;
  253.     $alpha=~tr/a-z/A-Z/;
  254.     }
  255.     
  256.     return $alpha;
  257.  
  258. }
  259.  
  260.  
  261. #######################################################################
  262. #
  263. # alphaHeader()
  264. #
  265. #######################################################################
  266.  
  267. sub alphaHeader{
  268.  
  269.     local($filehandle) = @_;
  270.     
  271.     local(@alphabet) = 
  272.     (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
  273.  
  274.     print {$filehandle} "${bBQ}<B>\n" or die "print: $!";
  275.  
  276.     foreach(@alphabet){
  277.     print {$filehandle} "<A HREF=\"#$_\">$_</A> \n"
  278.       or die "print: $!";
  279.     }
  280.  
  281.     print {$filehandle} "</B>${eBQ}<BR>\n"
  282.       or die "print: $!";
  283. }
  284.  
  285. #######################################################################
  286. #
  287. # alphaIndex($inBQ,$fd,$lastAlpha,$thisAlpha)
  288. #
  289. #######################################################################
  290.  
  291. sub alphaIndexIfNeeded{
  292.  
  293.     local($fd);
  294.     ($inBQ, $fd, $lastAlpha, $thisAlpha) = @_;
  295.  
  296.     local(@alphabet) = 
  297.     (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
  298.     
  299.     if($thisAlpha ne $lastAlpha && $thisAlpha ne ""){
  300.     if($inBQ == 1){
  301.         $exdent = "$eBQ\n";
  302.         $inBQ = 0;
  303.     }else{
  304.         $exdent = "";
  305.     }
  306.     
  307.     $off = (ord($thisAlpha)-ord($lastAlpha));
  308.     
  309.     print {$fd} $exdent or die "print: $!";
  310.  
  311.     if($off > 1 && $lastAlpha ne ""){
  312.         local($a) = 0;
  313.         while($lastAlpha ne $alphabet[$a]){
  314.         $a++;
  315.         }
  316.         $a = $a+1;
  317.         for($j=0;$j<$off;$j++){
  318.         print {$fd} "<H3><A NAME=\"$alphabet[$j+$a]\">" .
  319.             "$alphabet[$j+$a]</A></H3>\n"
  320.               or die "print: $!";
  321.         }
  322.     }else{
  323.         print {$fd} "<H3><A NAME=\"$thisAlpha\">" .
  324.         "$thisAlpha</A></H3>\n"
  325.           or die "print: $!";
  326.     }
  327.     }
  328.  
  329.     
  330.     $lastAlpha = $thisAlpha;
  331.     
  332. }
  333.